﻿using System.Linq;
using System.Web.Mvc;
using OurSite.Business.Event;
using OurSite.Business.Picture;
using OurSite.Business.Repositories;
using OurSite.Web.Models;
using OurSite.Web.HTMLHelpers;

namespace OurSite.Web.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        IPictureRepository pictureRepository = new PictureRepository();

        public ActionResult Index()
        {
            Event evt = new Event();
            evt.Name = "Our Favorites";
            //evt.Pictures = pictureRepository.GetTopFavoritePictures(15);
            evt.Pictures = pictureRepository.GetAllFavoritePictures().ToList();

            EventModel eventModel = new EventModel();
            eventModel.Event = evt;

            return View(eventModel);
        }

        public JsonResult Search(string searchTerm)
        {
            var query = new PictureQuery {Caption = searchTerm};
            var pictures = pictureRepository.Search(query);
            var returnHtml = HTMLHelper.PictureSearchResults(pictures);
            return Json(returnHtml, JsonRequestBehavior.AllowGet);
        }
    }
}
